﻿/*
=======================================================
    RoleDepartment【角色与部门】
=======================================================
*/

namespace Services
{
    public interface IRoleDepartmentMapping : IMapping<RoleDepartment, RoleDepartmentModel, RoleDepartmentFilterModel>
    { }

    public class RoleDepartmentMapping : AutoRoleDepartmentMapping, IRoleDepartmentMapping
    {
        public RoleDepartmentMapping(ICurrentUser currentUser)
            : base(currentUser)
        { }
        
        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override RoleDepartmentModel Entity2Model(RoleDepartment entity)
        {
            if (entity == null)
            {
                return null;
            }

            RoleDepartmentModel model = base.Entity2Model(entity);


            /***************************************** 下面处理自定义转换 *****************************************/



            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override RoleDepartment Model2Entity(RoleDepartmentModel model)
        {
            RoleDepartment entity = base.Model2Entity(model);


            /***************************************** 下面处理自定义转换 *****************************************/



            return entity;
        }
        #endregion

        #region 读数据(集合)
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entities">Entity对象</param>
        /// <returns></returns>
        public override List<RoleDepartmentModel> Entity2Model(IEnumerable<RoleDepartment> entities)
        {
            return entities.Select(x => Entity2Model(x)).ToList();
        }
        #endregion

        #region 写数据(集合)
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="models">ViewModel对象</param>
        /// <returns></returns>
        public override List<RoleDepartment> Model2Entity(IEnumerable<RoleDepartmentModel> models)
        {
            return models.Select(x => Model2Entity(x)).ToList();
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<RoleDepartment> FilterModel2Where(RoleDepartmentFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //SearchInput
            if (!string.IsNullOrEmpty(filterModel._SearchInput))
            { }


            return where;
        }
        #endregion
    }
}
